<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>


<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="rssgate.dao.PMF"%>
<%@page import="rssgate.dao.entity.Feed"%>
<%@page import="java.util.List"%>
<%@page import="rssgate.ManageCommandConstants"%>
<%@page import="com.google.appengine.api.datastore.Text"%><html>
<%
	final PersistenceManager pm = PMF.get().getPersistenceManager();
	final String query = "select from " + Feed.class.getName();
	final List<Feed> feeds = (List<Feed>) pm.newQuery(query).execute();
	for (Feed feed : feeds) {
		final Text subtitle = feed.getSubtitle();
		final Text title = feed.getTitle();
		String subtitleTxt="[UNUPDATED]";
		if(subtitle!=null)
		{
			subtitleTxt = subtitle.getValue();
		}
		String titleStr = "";
		if(title!=null)
		{
			titleStr = title.getValue();
		}
%>
<LINK REL="alternate" TITLE="<%=titleStr%>:<%=subtitleTxt %>" HREF="/rssgate/<%=feed.getId()%>" TYPE="application/rss+xml">
<%
	}
%>
<body>
<h1>List of RSSs</h1>
<%
	int i=0;
	for (Feed feed : feeds) {
		final Text subtitle = feed.getSubtitle();
		final Text title = feed.getTitle();
		String subtitleTxt="[UNUPDATED]";
		if(subtitle!=null)
		{
			subtitleTxt = subtitle.getValue();
		}
		String titleStr = "";
		if(title!=null)
		{
			titleStr = title.getValue();
		}
%>
<ul>
	<li>
		<b>
			<a href="/rssgate/<%=feed.getId()%>"><%=titleStr%>:<%=subtitleTxt%></a>
			<b>Last Update Data: <%=feed.getLastUpdate()%></b>
			<form action="/managerss" method="post">			    
		    	<input type="hidden" name="<%=ManageCommandConstants.COMMAND %>" value="<%=ManageCommandConstants.REMOVE_COMMAND %>"/>
		    	<input type="hidden" name="<%=ManageCommandConstants.VALUE_ID %>" value="<%=feed.getId()%>"/>	
		    	<input type="submit" value="Remove" />	    				    
		 	</form>
		 	<form action="/update" method="post">			    
		    	<input type="hidden" name="<%=ManageCommandConstants.COMMAND %>" value="<%=ManageCommandConstants.UPDATE_COMMAND %>"/>
		    	<input type="hidden" name="<%=ManageCommandConstants.VALUE_ID %>" value="<%=feed.getId()%>"/>	
		    	<input type="submit" value="Update" />	    				    
		 	</form>
		</b>
	</li>
</ul>
<%
	}
%>
<h1>Add RSS</h1>
 <form action="/managerss" method="post">
    <div>
    	<input type="hidden" name="<%=ManageCommandConstants.COMMAND %>" value="<%=ManageCommandConstants.ADD_COMMAND %>"/>
    	<input name="<%=ManageCommandConstants.VALUE_URL %>"></input>
    	<input type="submit" value="Add RSS" />
    </div>
  </form>

<%
	pm.close();
%>


</body>
</html>
